package com.crop.back.common.enums;

/**
 * 定义删除标志枚举类，用于表示实体是否被删除的状态
 */
import lombok.Getter;

public enum Deleted {

    /**
     * 表示实体已被删除的状态
     */
    DELETED(1, "已删除"),

    /**
     * 表示实体未被删除的状态
     */
    NOT_DELETED(0, "未删除");

    @Getter
    private int code;
    @Getter
    private String description;

    /**
     * 构造函数，初始化DeleteFlag枚举实例
     * @param code 枚举值，用于数据库存储
     * @param description 枚举的描述，用于UI展示或调试
     */
    Deleted(int code, String description) {
        this.code = code;
        this.description = description;
    }

    /**
     * 根据给定的值返回对应的DeleteFlag枚举实例
     * @param code 枚举值，根据此值查找对应的枚举实例
     * @return 对应的DeleteFlag枚举实例
     * @throws IllegalArgumentException 如果给定的值不存在于任何枚举实例，则抛出此异常
     */
    public static Deleted getDeleteFlagByCode(int code) {
        for (Deleted deleted : Deleted.values()) {
            if (deleted.getCode() == code) {
                return deleted;
            }
        }
        throw new IllegalArgumentException("Unknown value: " + code);
    }

}
